In logic, a three-valued logic (also trivalent, ternary, or trinary logic, sometimes abbreviated 3VL) is any of several many-valued logic systems in which there are three truth values indicating true, false and some indeterminate third value. This is contrasted with the more commonly known bivalent logics (such as classical sentential or boolean logic) which provide only for true and false. Conceptual form and basic ideas were initially created by Łukasiewicz, Lewis and Sulski. These were then re-formulated by Grigore Moisil in an axiomatic algebraic form, and also extended to n-valued logics in 1945.
Contents |
As with bivalent logic, truth values in ternary logic may be represented numerically using various representations of the ternary numeral system. A few of the more common examples are:
This article mainly illustrates a system of ternary propositional logic using the truth values {false, unknown, and true}, and extends conventional boolean connectives to a trivalent context. Ternary predicate logics exist as well; these may have readings of the quantifier different from classical (binary) predicate logic, and may include alternative quantifiers as well.
Below is a set of truth tables showing the logic operations for Kleene's logic.
A AND B | True | False | Unknown |
---|---|---|---|
True | True | False | Unknown |
False | False | False | False |
Unknown | Unknown | False | Unknown |
A OR B | True | False | Unknown |
---|---|---|---|
True | True | True | True |
False | True | False | Unknown |
Unknown | True | Unknown | Unknown |
A | NOT A |
---|---|
True | False |
False | True |
Unknown | Unknown |
In this truth table, the UNKNOWN state can be metaphorically thought of as a sealed box containing either an unambiguously TRUE or unambiguously FALSE value. The knowledge of whether any particular UNKNOWN state secretly represents TRUE or FALSE at any moment in time is not available. However, certain logical operations can yield an unambiguous result, even if they involve at least one UNKNOWN operand. For example, since TRUE OR TRUE equals TRUE, and TRUE OR FALSE also equals TRUE, one can infer that TRUE OR UNKNOWN equals TRUE, as well. In this example, since either bivalent state could be underlying the UNKNOWN state, but either state also yields the same result, a definitive TRUE results in all three cases.
If numeric values are assigned to FALSE, UNKNOWN and TRUE such that FALSE<UNKNOWN<TRUE, then A AND B AND C... = MIN(A,B,C...) and A OR B OR C ... = MAX(A,B,C...).
The database structural query language, SQL, implements ternary logic as a means of handling NULL field content. SQL uses NULL to represent missing data in a database. If a field contains no defined value, SQL assumes this means that an actual value exists, but that the value is not currently recorded in the database. Note that a missing value is not the same as either a numeric value of zero, or a string value of zero length. Comparing anything to NULL—even another NULL—results in an UNKNOWN truth state. For example, the SQL expression "City = 'Paris'
" resolves to FALSE for a record with "Chicago" in the City field, but it resolves to UNKNOWN for a record with a NULL City field. In other words, to SQL, an undefined field represents potentially any possible value: a missing city might or might not represent Paris.
Using ternary logic, SQL can then account for the UNKNOWN truth state in evaluating boolean expressions. Consider the expression "City = 'Paris' OR Balance < 0.0
". This expression resolves to TRUE for any record whose Balance field contains a negative number. Likewise, this expression is TRUE for any record with 'Paris' in its City field. The expression resolves to FALSE only for a record whose City field explicitly contains a string other than 'Paris', and whose Balance field explicitly contains a non-negative number. In any other case, the expression resolves to UNKNOWN. This is because a missing City value might be missing the string 'Paris', and a missing Balance might be missing a negative number. However, regardless of missing data, a boolean OR operation is FALSE only when both of its operands are also FALSE, so not all missing data leads to an UNKNOWN resolution.
In SQL Data Manipulation Language, a truth state of TRUE for an expression (e.g., in a WHERE
clause) initiates an action on a row (e.g. return the row), while a truth state of UNKNOWN or FALSE does not.[4] In this way, ternary logic is implemented in SQL, while behaving as binary logic to the SQL user.
SQL Check Constraints behave differently, however. Only a truth state of FALSE results in a violation of a check constraint. A truth state of TRUE or UNKNOWN indicates a row has been successfully validated against the check constraint.[5]